package com.alipay.api.test.fsf;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
/**
 * 2017-07-21 
 * 欢迎访问支付宝论坛：https://openclub.alipay.com/index.php
 */
public class Alipaytradeapppay {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
 
		String APP_ID="2016091200495918";
		String APP_PRIVATE_KEY="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXFPoT2ozxE8X3onHpEW+nXA9JOZZdNpbprRu9+XOXuq6b3mHf2qMe+LfHH+1vMAdXzIrugRpa6OedxfuWUyF5PEFFfGV//5NoyA/II5/scmxVFo+75pjLnYqg8tPAhDiiRF7iTi/9OZbLRmpUulCQfUQ37gRQlRZXT8/mMuM9X2EcbNDf749y/z/G+U0GX9jOPW/AHqekxbfXLkzS6avqo/Sqg8Sa0SnafkyOyQAPVPy2uBJFcTStrmTcyrG1+HC3HPEMsOXUBtM+GveefE/np3+uFloIQeaV9Rg6PPBDBgiD30ALdVbhkDdV7oBAGB1zFtXZ3WQhNK8eaSFk0I8jAgMBAAECggEBAIM7J1XjepVVFZpaMhO+n3uBzY1PRjrFViS3xucnLK7Y6x5c9isZoKMga5G9O+Jel6I9+1fcMGZS9AzpkfUrVGIYYqHWwduCxio3zO2NdDZP1aW7KTKPxJzoxSe0hRYuQ3s/ZCOywqB0S3VaPrZF+ADprj3es0TDm1pP60gLX7NINWeJicnGP8LjidYZsI3kDacRxwVSA1Lfsp8cL+lZYsfJgfSZABDYuN1tdIv2rCrs6Rz3LbjRCvbuwIs6pSakjfqCwizNEwvYrBg4KO7GKmNeY9qvf3Ii/Y/tkR5QctWBTpweJA6K8M3/0i5g7Im2AT8INCUsB0eGKqScSnDhfeECgYEA02vp5sY/sCMleEcYGgMy0whDintipkLmIjXARc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0/P5jLjPV9hHGzQ3++Pcv8/xvlNBl/Yzj1vwB6npMW31y5M0umr6qP0qoPEmtEp2n5MjskAD1T8trgSRXE0ra5k3MqxtfhwtxzxDLDl1AbTPhr3nnxP56d/rhZaCEHmlfUYOjzwQwYIg99AC3VW4ZA3Ve6AQBgdcxbV2d1kITSvHmkhZNCPIwIDAQAB";
		//签名方式
		String sign_type="RSA2";
		//编码格式
		String CHARSET="utf-8";
		//正式环境支付宝网关，如果是沙箱环境需更改成https://openapi.alipaydev.com/gateway.do
		//String url="https://openapi.alipay.com/gateway.do";
		String url="https://openapi.alipaydev.com/gateway.do";
		//实例化客户端
		AlipayClient alipayClient = new DefaultAlipayClient(url, APP_ID, APP_PRIVATE_KEY, "json", CHARSET, ALIPAY_PUBLIC_KEY,sign_type);
		//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
		AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
		//SDK已经封装掉了公共参数，这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
		AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
		model.setBody("我是测试数据");
		model.setSubject("App支付测试Java");
		//请保证OutTradeNo值每次保证唯一
		model.setOutTradeNo("2017090080001939235");
		model.setTimeoutExpress("30m");
		model.setTotalAmount("0.01");
		model.setProductCode("QUICK_MSECURITY_PAY");
		request.setBizModel(model);
		request.setNotifyUrl("www.baidu.com");
		try {
		        //这里和普通的接口调用不同，使用的是sdkExecute
		        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
		        System.out.println(response.getBody());//就是orderString 可以直接给客户端请求，无需再做处理。
		    } catch (AlipayApiException e) {
		        e.printStackTrace();
		}
	}

}
